﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace CodeGen.TS.Input.XmlConfig
{


    [Serializable()]
    [System.Xml.Serialization.XmlRoot("config", Namespace="http://adrianehrsam.ch/XMLConfig.xsd")]
    public class ConfigRoot
    {


        [XmlArray("configgroups")]
        [XmlArrayItem("configgroup", Type = typeof(ConfigGroup))]
        public ConfigGroup[] ConfigurationGroups { get; set; }

        public static ConfigRoot FromXMLFile(string fileName)
        {
           
            XmlSerializer serializer = new XmlSerializer(typeof(ConfigRoot));

            using (StreamReader reader = new StreamReader(fileName))
            {
                ConfigRoot root = (ConfigRoot)serializer.Deserialize(reader);
                return root;
            }
        }
    }

    public class ConfigGroup
    {
        [XmlElement("configuration")]
        public Configuration Configuration { get; set; }


        [XmlArray("types")]
        [XmlArrayItem("type", Type = typeof(TypesConfig))]
        public TypesConfig[] TypeConfigs { get; set; }
    }

    public class Configuration
    {
        [XmlAttribute("output")]
        public string Output { get; set; }
        [XmlAttribute("sourcedll")]
        public string SourceDll { get; set; }

        [XmlAttribute("modul")]
        public string ModulName { get; set; }

        [XmlAttribute("recursionLevel")]
        public int RecursionLevel { get; set; }
    }



    [Serializable]
    public class TypesConfig
    {
        public TypesConfig()
        {
            RecursionLevel = int.MinValue;//Not set
        }

        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlAttribute("sourcedll")]
        public string SourceDll { get; set; }

        [XmlAttribute("fqname")]
        public string FullQualifiedName { get; set; }

        [XmlAttribute("generate")]
        public string Generate { get; set; }

        [XmlAttribute("useobservable")]
        public bool UseObservable { get; set; }
        [XmlAttribute("useinitialvalue")]
        public bool UseInitialValue { get; set; }
        [XmlAttribute("webservicemethod")]
        public string GeneratedWebserviceMethod { get; set; }

        [XmlAttribute("output")]
        public string Output { get; set; }

        [XmlAttribute("newname")]
        public string NewName { get; set; }


        [XmlAttribute("modul")]
        public string ModulName { get; set; }
        //name="Hans" generate="class" useobservable="" useinitalvalue="" generatedwebservicemethod=""

        [XmlAttribute("recursionLevel")]
        public int RecursionLevel { get; set; }

        [XmlIgnore]
        public Type CLRType { get; set; }

    }
}
